<?php
	require(__DATAGEN_CLASSES__ . '/TableProjectRequestCancelGen.class.php');

	/**
	 * The TableProjectRequestCancel class defined here contains any
	 * customized code for the TableProjectRequestCancel class in the
	 * Object Relational Model.  It represents the "table_project_request_cancel" table 
	 * in the database, and extends from the code generated abstract TableProjectRequestCancelGen
	 * class, which contains all the basic CRUD-type functionality as well as
	 * basic methods to handle relationships and index-based loading.
	 * 
	 * @package My Application
	 * @subpackage DataObjects
	 * 
	 */
	class TableProjectRequestCancel extends TableProjectRequestCancelGen {
		/**
		 * Default "to string" handler
		 * Allows pages to _p()/echo()/print() this object, and to define the default
		 * way this object would be outputted.
		 *
		 * Can also be called directly via $objTableProjectRequestCancel->__toString().
		 *
		 * @return string a nicely formatted string representation of this object
		 */
		public function __toString() {
			return sprintf('%s',  $this->intId);
		}

        //loders
        public static function load_request_id_for_project($project_id_)
        {
            $objDatabase = TableProjectRequestCancel::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

          $strQuery = 'SELECT id FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_;

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return $objResult['id'];

            return false;
        }
        
        public function count_bid_for_this_project()
        {
            $objDatabase = TableProjectRequestCancel::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

        echo $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE id='.$this->Id.' and status=0';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();

            return $objResult[0];
        }
        public function count_bid_for_acccep_complete()
        {
              $objDatabase = TableProjectRequestCancel::GetDatabase();
            //$strParam1 = $objDatabase->SqlVariable($strParam1);

     echo  $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE id='.$this->Id.' and status=3 or status=2 or status = 1 ';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();

            return $objResult[0];
        }
         public function count_bid_for_decline_cancel()
        {
              $objDatabase = TableProjectRequestCancel::GetDatabase();
            //$strParam1 = $objDatabase->SqlVariable($strParam1);

      echo $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE id='.$this->Id.' and status=2 or status=3 or status = 1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();

            return $objResult[0];
        }
            public function count_bid_for_retract_cancel()
        {
              $objDatabase = TableProjectRequestCancel::GetDatabase();
            //$strParam1 = $objDatabase->SqlVariable($strParam1);

     echo  $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE id='.$this->Id.' and status=1 or status=2 or status =3';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();

            return $objResult[0];
        }


        //properties
        public function bool_cancel_request_from_me($key_)
        {
            if($this->BuyerId==$key_)
            {
                return true;
            }
            return false;
        }

        public function bool_cancel_for_the_project($key_)
        {
            if($this->ProjectId==$key_)
            {
                return true;
            }
            return false;
        }

        public function bool_cancel_request_to_me($key_)
        {
            if($this->ProviderId==$key_)
            {
                return true;
            }
            return false;
        }

        //created & active
        public function bool_created()
        {
            if($this->Status==0)
            {
                return true;
            }
            return false;
        }

        //retracted
        public function bool_retracted()
        {
            if($this->Status==1)
            {
                return true;
            }
            return false;
        }

        //declined(denied)
        public function bool_declined()
        {
            if($this->Status==2)
            {
                return true;
            }
            return false;
        }

        //accepted & the project is cancelled
        public function bool_accepted()
        {
            if($this->Status==3)
            {
                return true;
            }
            return false;
        }

        //created & active
        public function set_status_created()
        {
            $this->Status=0;
        }

        //retracted
        public function set_status_retracted()
        {
            $this->Status=1;
        }

        //declined(denied)
        public function set_status_declined()
        {
            $this->Status=2;
        }

        //accepted & the project is cancelled
        public function set_status_accepted()
        {
            $this->Status=3;
        }

        //reason
        public function bool_reason_agreed()
        {
            if($this->CancelType==0)
            {
                return true;
            }
            return false;
        }

        public function bool_reason_mismatched()
        {
            if($this->CancelType==1)
            {
                return true;
            }
            return false;
        }

        public function bool_reason_comminication()
        {
            if($this->CancelType==2)
            {
                return true;
            }
            return false;
        }

        public function bool_reason_delaying()
        {
            if($this->CancelType==3)
            {
                return true;
            }
            return false;
        }

        public function bool_reason_other()
        {
            if($this->CancelType==4)
            {
                return true;
            }
            return false;
        }
        
        public function set_reason_agreed()
        {
            $this->CancelType=0;
        }
        
        public function set_reason_mismatched()
        {
            $this->CancelType=1;
        }

        public function set_reason_comminication()
        {
            $this->CancelType=2;
        }

        public function set_reason_delaying()
        {
            $this->CancelType=3;
        }

        public function set_reason_other()
        {
            $this->CancelType=4;
        }


        //functions
        public function set_request_date_for_now()
        {
            $this->RequestDate=QDateTime::Now();
        }
        public function set_accept_date_for_now()
        {
            $this->AcceptDate=QDateTime::Now();
        }
        public function set_decline_date_for_now()
        {
            $this->DeclineDate=QDateTime::Now();
        }
        public function set_retract_date_for_now()
        {
            $this->RetractDate=QDateTime::Now();
        }
         
        
        public function get_textlink_to_request_cancel_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_request_cancel_popup().'">'.'[select provider]'.'</a>';
        }
          public function get_href_to_request_cancel_popup()
        {
            return '/popup_select_bid.php?id='.$this->Project->Id.'&rid='.$this->Id;
        }
       
		public function bool_active()
        {
            if($this->Status==0)
            {
                return true;
            }
            return false;
        }


		// Override or Create New Load/Count methods
		// (For obvious reasons, these methods are commented out...
		// but feel free to use these as a starting point)
/*
		public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses = null) {
			// This will return an array of TableProjectRequestCancel objects
			return TableProjectRequestCancel::QueryArray(
				QQ::AndCondition(
					QQ::Equal(QQN::TableProjectRequestCancel()->Param1, $strParam1),
					QQ::GreaterThan(QQN::TableProjectRequestCancel()->Param2, $intParam2)
				),
				$objOptionalClauses
			);
		}

		public static function LoadBySample($strParam1, $intParam2, $objOptionalClauses = null) {
			// This will return a single TableProjectRequestCancel object
			return TableProjectRequestCancel::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::TableProjectRequestCancel()->Param1, $strParam1),
					QQ::GreaterThan(QQN::TableProjectRequestCancel()->Param2, $intParam2)
				),
				$objOptionalClauses
			);
		}

		public static function CountBySample($strParam1, $intParam2, $objOptionalClauses = null) {
			// This will return a count of TableProjectRequestCancel objects
			return TableProjectRequestCancel::QueryCount(
				QQ::AndCondition(
					QQ::Equal(QQN::TableProjectRequestCancel()->Param1, $strParam1),
					QQ::Equal(QQN::TableProjectRequestCancel()->Param2, $intParam2)
				),
				$objOptionalClauses
			);
		}

		public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses) {
			// Performing the load manually (instead of using QCubed Query)

			// Get the Database Object for this Class
			$objDatabase = TableProjectRequestCancel::GetDatabase();

			// Properly Escape All Input Parameters using Database->SqlVariable()
			$strParam1 = $objDatabase->SqlVariable($strParam1);
			$intParam2 = $objDatabase->SqlVariable($intParam2);

			// Setup the SQL Query
			$strQuery = sprintf('
				SELECT
					`table_project_request_cancel`.*
				FROM
					`table_project_request_cancel` AS `table_project_request_cancel`
				WHERE
					param_1 = %s AND
					param_2 < %s',
				$strParam1, $intParam2);

			// Perform the Query and Instantiate the Result
			$objDbResult = $objDatabase->Query($strQuery);
			return TableProjectRequestCancel::InstantiateDbResult($objDbResult);
		}
*/




		// Override or Create New Properties and Variables
		// For performance reasons, these variables and __set and __get override methods
		// are commented out.  But if you wish to implement or override any
		// of the data generated properties, please feel free to uncomment them.
/*
		protected $strSomeNewProperty;

		public function __get($strName) {
			switch ($strName) {
				case 'SomeNewProperty': return $this->strSomeNewProperty;

				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		public function __set($strName, $mixValue) {
			switch ($strName) {
				case 'SomeNewProperty':
					try {
						return ($this->strSomeNewProperty = QType::Cast($mixValue, QType::String));
					} catch (QInvalidCastException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				default:
					try {
						return (parent::__set($strName, $mixValue));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}
*/
	}
?>